// CreditsState.cpp: implementation of the CreditsState class.
//
//////////////////////////////////////////////////////////////////////

#include "CreditsState.h"

#ifdef FREEGLUT_IS_PRESENT
#  include <GL/freeglut.h>
#else
#  ifdef __APPLE__
#    include <GLUT/glut.h>
#  else
#    include <GL/glut.h>
#  endif
#endif

#include "ui.h"
#include "BackGroundImage.h"
#include "ImageButton.h"
#include "Mouse.h"
#include "Keyboard.h"

#include "tinyxml2/tinyxml2.h"

using namespace tinyxml2;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CreditsState::CreditsState()
{
this->oldState = NULL;
this->load("CreditsState.xml");
}

CreditsState::CreditsState(State* oldState)
{
this->oldState = oldState;
this->load("CreditsState.xml");
}

CreditsState::~CreditsState()
{
	delete scene;
	
	delete backgroundImage;
	delete backButton;
	delete ms;
	delete kb;
}

void CreditsState::load(const char* filename)
{
	scene = new uiScene(filename);

	this->kb = new Keyboard();
	this->ms = new Mouse();
	
	nextState = this;
}

void CreditsState::display(void)
{
	scene->display();
	
//backgroundImage->display();
//backButton->display();
}

void CreditsState::reset()
{
this->nextState = this;
}

void CreditsState::resize(int w, int h)
{

}

void CreditsState::keyUp(unsigned char key, int x, int y)
{
kb->read(key,GLUT_UP,x,y);
}

void CreditsState::keyDown(unsigned char key, int x, int y)
{
kb->read(key,GLUT_DOWN,x,y);
}

void CreditsState::specialUp(int key, int x, int y)
{
kb->read(key,GLUT_UP,x,y);
}

void CreditsState::specialDown(int key, int x, int y)
{
kb->read(key,GLUT_DOWN,x,y);
}

void CreditsState::motion(int newx, int newy)
{
	scene->motion(newx, newy);
}

void CreditsState::passive(int newx, int newy)
{
//backButton->mouse(-1,-1,newx,newy);
	scene->passive(newx, newy);
}

void CreditsState::mouse(int button, int state, int x, int y)
{
//if(backButton->mouse(button,state,mouseX,mouseY)) this->nextState = this->oldState;
	scene->mouse(button,state,x,y);
}

State* CreditsState::idle(void)
{
if(kb->isPressed(27)) exit(0);
if(nextState == this) return nextState;
else {State* tmpState = nextState; this->reset(); return tmpState;}
}

